package com.example.sample.vpn;


import android.util.Log;

public class VpnNative {

    private static final String TAG = "VpnNative";

    static {
        System.loadLibrary("aa");
        VpnNative.getInstance();
    }

    private static VpnNative mInstance = null;
    public static VpnNative getInstance(){
        if (mInstance == null){
            mInstance = new VpnNative();
            mInstance.nativeInit();
        }
        return mInstance;
    }

    public static native void parase(Object fd);

    public static native void startForwarder(int port);

    /**
     * native初始化，把this传给native层保存
     */
    private native void nativeInit();

    /**
     * 判断透传属性是否已知，供native调用
     * @param ip
     * @return
     */
    public int needForward(String ip){
        return ForwardManager.getInstance().needForward(ip);
    }

    /**
     * 保存透传属性，供native调用
     * @param ip
     * @param forward
     */
    public void saveForward(String ip, int forward){
        ForwardManager.getInstance().saveForward(ip, forward);
    }

    /**
     * 检查IP是否是游戏使用的IP
     */
    public void checkForward(String srcIp, String dstIp, int type){
        Log.i(TAG, "checkForward "+srcIp+" "+dstIp+" "+type);
    }

    /**
     * VPN保护socket
     * @param fd
     */
    public void protectSocket(int fd){
        Log.i(TAG, "protectSocket "+fd);
        MyVpnService svc = MyVpnService.getInstance();
        if (svc != null){
            svc.protect(fd);
        }
    }
    
    /**
     * 是否游戏UID
     * @param fd
     */
    public int isGameUid(int uid){
    	return ForwardManager.getInstance().isGameUid(uid) ? 1 : 0;
    }
}
